package cn.fl.audit.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.dto.AudCarInfoDTO;
import cn.fl.audit.service.IAudCarInfoService;
import cn.fl.audit.service.IAuditApiService;
import cn.fl.audit.transform.AudCarInfoVOTransform;
import cn.fl.audit.vo.AudCarInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.IAuditCarInfoService;
import cn.fl.preloan.condition.AuditCarInfoQueryCondition;
import cn.fl.preloan.dto.audit.AudCarInfoListRequest;
import cn.fl.preloan.dto.audit.AuditCarInfoDTO;
import cn.fl.commons.result.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 信审整体资料车辆信息 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AudCarInfoServiceImpl implements IAudCarInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(AudCarInfoServiceImpl.class);
	
	@Autowired
	private IAuditApiService auditApiService;

	@Autowired
	private IAuditCarInfoService auditCarInfoService;

	@Override
	public AudCarInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudCarInfoDTO dto = null;//this.自定义ApiService.selectById(id);
		return AudCarInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(AudCarInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//return this.audCarInfoApiService.add(AudCarInfoVOTransform.toDTO(entity));
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audCarInfoApiService.removeById(id);
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AudCarInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audCarInfoApiService.modify(AudCarInfoVOTransform.toDTO(entity));
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.audCarInfoApiService.searchListPage(page);
		return null;
	}

	@Override
	public List<AudCarInfoVO> searchList(AuditCarInfoQueryCondition qc) throws BaseException {
		if(null==qc) qc = new AuditCarInfoQueryCondition();
		AudCarInfoListRequest listRequest = new AudCarInfoListRequest(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		ResponseData<List<AuditCarInfoDTO>> responseData = auditCarInfoService.searchList(listRequest);
		List<AudCarInfoVO> VOList = new ArrayList<>();
		if (responseData != null && ResponseData.SUCCESS_CODE.equals(responseData.getCode()) && CollectionUtils.isNotEmpty(responseData.getData())) {
			List<AuditCarInfoDTO> data = responseData.getData();
			for (AuditCarInfoDTO dto : data) {
				AudCarInfoVO vo = new AudCarInfoVO();
				BeanUtils.copyProperties(dto, vo);
				vo.setPeferPc(dto.getReferPc());
				VOList.add(vo);
			}
		}
		//转换金额
		if(CollectionUtils.isNotEmpty(VOList)){
			for (AudCarInfoVO audCarInfoVO : VOList) {
				if(null!=audCarInfoVO && null!=audCarInfoVO.getGuidePc()){
					audCarInfoVO.setGuidePcDouble(DecimalUtils.convertFenToYuan(audCarInfoVO.getGuidePc()));
				}
				if(null!=audCarInfoVO && null!=audCarInfoVO.getPeferPc()){
					audCarInfoVO.setPeferPcDouble(DecimalUtils.convertFenToYuan(audCarInfoVO.getPeferPc()));
				}
			}
		}
		return VOList;
	}
}
